<template>
  <el-form ref="formRef" :model="form" label-position="top" :label-width="140">
    <div class="v-title my-3">退货信息</div>
    <div class="grid grid-cols-2 gap-x-3">
      <div class="mb-2">
        <strong>供应商: </strong> {{ form.supplier_name }}
      </div>
      <div>
        <strong>仓库: </strong> {{ form.destination_warehouse_name }}
      </div>
      <el-form-item label="收件人">
        <el-input v-model="form.contact_name" placeholder="收件人" class="w-full" />
      </el-form-item>
      <el-form-item label="联系电话">
        <el-input v-model="form.contact_tel" placeholder="联系电话" class="w-full" />
      </el-form-item>
      <el-form-item label="收货地址" class="col-span-2">
        <Area v-model="form" field="return" />
      </el-form-item>
    </div>
    <div class="grid grid-cols-3 gap-x-3">
      <el-form-item label="退货方式">
        <el-radio-group v-model="form.return_method">
          <el-radio v-for="(d, i) in options.return_method" :label="d.value">{{ d.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="承担运费">
        <el-radio-group v-model="form.tracking_carrier">
          <el-radio v-for="(d, i) in options.tracking_carrier" :label="d.value">{{ d.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="垫付运费">
        <el-radio-group v-model="form.is_prepay">
          <el-radio v-for="(d, i) in options.is_prepay" :label="d.value">{{ d.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
    </div>
    <el-form-item label="退货数量">
      <el-input-number v-model="form.process_num" controls-position="right" :min="0" :step="1" :precision="0"
        class="w-full" disabled />
    </el-form-item>
    <div>是否确认该sku退货完成后，完结该sku的入库，不再补货？</div>
  </el-form>
</template>

<script setup>
import api from '../../api'
import Area from '@/components/Area'
const props = defineProps({
  modelValue: { type: Object, default: () => ({}) },
  options: { type: Object, default: () => ({}) },
})
const emit = defineEmits(['update:modelValue'])
const form = computed({
  get() {
    return props.modelValue
  },
  set(val) {
    emit('update:modelValue', val)
  }
})
const { a_id, ps_id } = props.modelValue
api.getSku({ a_id, ps_id }).then(res => {
  form.value = Object.assign(form.value, res.data)
})
const formRef = ref()
const validate = async () => await formRef?.value.validate(res => res)
defineExpose({ validate })
</script>